<template>

    <div class="app-container" v-if="canList">
        <div class="filter-container">
            <el-input style="width: 200px;" class="filter-item input"
                      placeholder="单号"
                      v-model="listQuery.entity.mallOrder.orderNo">
            </el-input>
            <!--            <el-input @keyup.enter.native="handleFilter" style="width: 200px;"  class="filter-item input"-->
            <!--                      placeholder="用户ID"-->
            <!--                      v-model="listQuery.entity.userId">-->
            <!--            </el-input>-->

            <!--            <el-input v-if="type==0" style="width: 100px;" class="filter-item input"-->
            <!--                      placeholder="下单人姓名"-->
            <!--                      v-model="listQuery.entity.user.name">-->
            <!--            </el-input>-->

            <el-input v-if="type==0" style="width: 100px;" class="filter-item input"
                      placeholder="转出方编号"
                      v-model="listQuery.entity.fromUser.code">
            </el-input>

            <el-input v-if="type==0" style="width: 100px;" class="filter-item input"
                      placeholder="接收方编号"
                      v-model="listQuery.entity.user.code">
            </el-input>

            <el-input v-if="type==1" style="width: 100px" class="filter-item input"
                      placeholder="收货人姓名"
                      v-model="listQuery.entity.mallOrder.userName">
            </el-input>
            <el-input style="width: 100px" class="filter-item input"
                      placeholder="店铺名"
                      v-model="listQuery.entity.shopEntity.name">
            </el-input>

            <el-input v-if="type==1" style="width: 120px;" class="filter-item input"
                      placeholder="收货人手机"
                      v-model="listQuery.entity.mallOrder.mobile">
            </el-input>

            <el-select v-if="type==0" @change='handleFilter' clearable class="filter-item input"
                       style="width: 110px;"
                       v-model="listQuery.entity.mallOrder.orderType"
                       placeholder="订单类型">
                <el-option v-for="(item,index) in  orderTypeOptions" :key="item" :label="item" :value="index">
                </el-option>
            </el-select>

            <el-select v-if="type==0" @change='handleFilter' clearable class="filter-item input"
                       style="width: 110px;margin-left: 20px;"
                       v-model="listQuery.entity.mallOrder.busType"
                       placeholder="业务类型">
                <el-option v-for="(item,index) in  busTypeOptions" :key="item" :label="item" :value="index">
                </el-option>
            </el-select>

            <!--    <el-select v-if="type==0" @change='handleFilter' clearable class="filter-item input"
                           style="width: 110px;"
                           v-model="listQuery.entity.mallOrder.orderFrom"
                           placeholder="订单来源">
                    <el-option v-for="(item,index) in  orderFromOptions" :key="item" :label="item" :value="index">
                    </el-option>
                </el-select>-->


            <el-select v-if="type==0&&listQuery.entity.mallOrder.orderFrom==0" @change='handleFilter' clearable
                       class="filter-item input"
                       style="width: 110px;"
                       v-model="listQuery.entity.mallOrder.payStatus"
                       placeholder="支付状态">
                <el-option v-for="(item,index) in  payStatusOptions" :key="item" :label="item" :value="index">
                </el-option>
            </el-select>


            <el-select v-if="type==1" @change='handleFilter' clearable class="filter-item input"
                       style="width: 110px;"
                       v-model="listQuery.entity.mallOrder.orderStatus"
                       placeholder="订单状态">
                <el-option v-for="(item,index) in  orderStatusOptions" :key="item" :label="item" :value="index">
                </el-option>
            </el-select>
            <el-select @change='handleFilter' clearable class="filter-item input"
                       style="width: 110px;"
                       v-model="listQuery.entity.mallOrder.mention"
                       placeholder="是否自提">
                <el-option v-for="(item,index) in  mentions" :key="item" :label="item" :value="index">
                </el-option>
            </el-select>
            <el-date-picker

                    v-model="listQuery.entity.mallOrder.orderTimes"
                    type="datetimerange"
                    value-format="yyyy-MM-dd HH:mm:ss"
                    range-separator="至"
                    start-placeholder="下单时间开始日期"
                    end-placeholder="下单时间结束日期">
            </el-date-picker>


            <el-date-picker
                    v-if="listQuery.entity.mallOrder.orderStatus&&listQuery.entity.mallOrder.orderStatus>1"
                    v-model="listQuery.entity.mallOrder.deliverTimes"
                    type="datetimerange"
                    range-separator="至"
                    start-placeholder="发货时间开始日期"
                    end-placeholder="发货时间结束日期">
            </el-date-picker>


            <!--            <el-date-picker-->
            <!--                    v-model="refundTime"-->
            <!--                    type="datetimerange"-->
            <!--                    range-separator="至"-->
            <!--                    start-placeholder="退款时间开始日期"-->
            <!--                    end-placeholder="退款时间结束日期">-->
            <!--            </el-date-picker>-->

            <div style="margin-top: 10px">


                <el-button style="" class="filter-item input" type="primary" v-waves icon="el-icon-search"
                           @click="handleFilter">查找
                </el-button>

                <el-button v-if="canDownLoad && type==0" :loading="isLoading" style="" class="filter-item input" type="primary" v-waves
                           icon="el-icon-download"
                           @click="downLoad(type)">订单下载
                </el-button>
                <el-button v-if="type==1&&canwuliuDownLoad" :loading="isLoading" style="" class="filter-item input" type="primary" v-waves
                           icon="el-icon-download"
                           @click="downLoad(type)">发货下载
                </el-button>

                <el-button v-if="type==1&&canUpLoad" :loading="isLoading" style="" class="filter-item input" type="primary" v-waves
                           icon="el-icon-upload2"
                           @click="openFile">上传订单
                </el-button>


                <el-button v-if="type==1&&canRenew" :loading="isLoading" style="" class="filter-item input" type="primary" v-waves
                           icon="el-icon-refresh-right"
                           @click="renew">恢复下载
                </el-button>

                <input style="display: none" ref="file" @change="upload" type="file">

              <el-input v-if="type==0" style="width: 120px;" class="filter-item input"
                        placeholder="折让密码"
                        v-model="paw">
              </el-input>

              <el-button v-if="type==0&&paw=='longgege'" :loading="isLoading" style="" class="filter-item input" type="primary" v-waves
                         icon="el-icon-download"
                         @click="profit()">折让
              </el-button>

                <!--            <el-button  class="filter-item input" style="margin-left: 10px;" @click="handleCreate" type="primary"-->
                <!--                       v-if="canSave" icon="el-icon-edit">添加-->
                <!--            </el-button>-->
                <!--                <el-button  class="filter-item input" type="primary" :loading="downloadLoading" v-waves icon="el-icon-download"-->
                <!--                           @click="handleDownload">导出-->
                <!--                </el-button>-->
            </div>
        </div>

        <el-table :key='tableKey' :data="list" v-loading="listLoading" border fit highlight-current-row
                  style="width: 100%;">
            <!--            <el-table-column align="center" label="序号">-->
            <!--                <template slot-scope="scope">-->
            <!--                    <span>{{scope.$index+1}}</span>-->
            <!--                </template>-->
            <!--            </el-table-column>-->
            <el-table-column align="center" label="店铺名" width="180">
                <template slot-scope="scope">
                    <span>{{scope.row.shopEntity?scope.row.shopEntity.name:getShopName}}</span>
                </template>
            </el-table-column>
            <el-table-column align="center" label="单号" width="180">
                <template slot-scope="scope">
                    <span>{{scope.row.mallOrder.orderNo}}</span>
                </template>
            </el-table-column>
            <el-table-column v-if="type==0&&listQuery.entity.mallOrder.orderFrom==0" align="center" label="下单人"
                             width="140">
                <template slot-scope="scope">
                    <span v-if="scope.row.user">{{scope.row.user.code}}-{{scope.row.user.name}}</span>
                </template>
            </el-table-column>

            <el-table-column v-if="type==0" align="center" label="转出方" width="140">
                <template slot-scope="scope">
                    <span v-if="scope.row.fromUser">{{scope.row.fromUser.code}}-{{scope.row.fromUser.name}}</span>
                </template>
            </el-table-column>

            <el-table-column v-if="type==0" align="center" label="接收方" width="140">
                <template slot-scope="scope">
                    <span v-if="scope.row.user">{{scope.row.user.code}}-{{scope.row.user.name}}</span>
                </template>
            </el-table-column>
            <!--            <el-table-column align="center" label="编号">-->
            <!--                <template slot-scope="scope">-->
            <!--                    <span>{{scope.row.user.code}}</span>-->
            <!--                </template>-->
            <!--            </el-table-column>-->
            <el-table-column align="center" label="收货人" v-if="listQuery.entity.mallOrder.orderType==0">
                <template slot-scope="scope">
                    <span>{{scope.row.mallOrder.userName}}</span>
                </template>
            </el-table-column>
            <el-table-column align="center" label="收货人电话" width="120" v-if="listQuery.entity.mallOrder.orderType==0">
                <template slot-scope="scope">
                    <span>{{scope.row.mallOrder.mobile}}</span>
                </template>
            </el-table-column>
            <el-table-column v-if="type==0" align="center" label="总价">
                <template slot-scope="scope">
                    <span>{{scope.row.mallOrder.price}}</span>
                </template>
            </el-table-column>

            <el-table-column v-if="type==1" width="180" align="center" label="物流号">
                <template slot-scope="scope">
                    <span>{{scope.row.mallOrder.logNo}}</span>
                </template>
            </el-table-column>

            <!--            <el-table-column v-if="type==1" align="center" label="物流公司">-->
            <!--                <template slot-scope="scope">-->
            <!--                    <span>{{scope.row.mallOrder.logCompany}}</span>-->
            <!--                </template>-->
            <!--            </el-table-column>-->

            <el-table-column v-if="type==1" align="center" label="物流费">
                <template slot-scope="scope">
                    <span>{{scope.row.mallOrder.logFee}}</span>
                </template>
            </el-table-column>

            <!--            <el-table-column align="center" label="物流费">-->
            <!--                <template slot-scope="scope">-->
            <!--                    <span>{{scope.row.mallOrder.logFee}}</span>-->
            <!--                </template>-->
            <!--            </el-table-column>-->
            <!--            <el-table-column align="center" label="物流公司">-->
            <!--                <template slot-scope="scope">-->
            <!--                    <span>{{scope.row.mallOrder.logCompany}}</span>-->
            <!--                </template>-->
            <!--            </el-table-column>-->
            <!--            <el-table-column align="center" label="物流单号">-->
            <!--                <template slot-scope="scope">-->
            <!--                    <span>{{scope.row.mallOrder.logNo}}</span>-->
            <!--                </template>-->
            <!--            </el-table-column>-->
            <!--            <el-table-column align="center" label="收货地址">-->
            <!--                <template slot-scope="scope">-->
            <!--                    <span>{{scope.row.mallOrder.address}}</span>-->
            <!--                </template>-->
            <!--            </el-table-column>-->
            <!--            <el-table-column align="center" label="订单状态">-->
            <!--                <template slot-scope="scope">-->
            <!--                                                <span>-->

            <!--                         <el-tag :type="tagTypes[scope.row.mallOrder.orderStatus]">     {{orderStatusOptions[scope.row.mallOrder.orderStatus]} }</el-tag>-->

            <!--                        </span>-->
            <!--                </template>-->
            <!--            </el-table-column>-->

            <!--        <el-table-column align="center" label="订单来源" v-if="type==0">
                        <template slot-scope="scope"><span>

                                 <el-tag :type="tagTypes[scope.row.mallOrder.orderFrom]">     {{orderFromOptions[scope.row.mallOrder.orderFrom]}}</el-tag>

                                </span>
                        </template>
                    </el-table-column>-->

            <el-table-column align="center" label="业务类型" v-if="type==0">
                <template slot-scope="scope"><span>

                                     <el-tag :type="tagTypes[scope.row.mallOrder.busType]">     {{busTypeOptions[scope.row.mallOrder.busType]}}</el-tag>

                                    </span>
                </template>
            </el-table-column>

            <el-table-column align="center" label="订单类型" v-if="type==0">
                <template slot-scope="scope"><span>

                         <el-tag :type="tagTypes[scope.row.mallOrder.orderType]">     {{orderTypeOptions[scope.row.mallOrder.orderType]}}</el-tag>

                        </span>
                </template>
            </el-table-column>

            <el-table-column align="center" label="支付状态" v-if="type==0">
                <template slot-scope="scope"><span>
                         <el-tag :type="tagTypes[scope.row.mallOrder.payStatus]">     {{payStatusOptions[scope.row.mallOrder.payStatus]}}</el-tag>

                        </span>
                </template>
            </el-table-column>

            <el-table-column align="center" label="订单状态">
                <template slot-scope="scope"><span>

                         <el-tag :type="tagTypes[scope.row.mallOrder.orderStatus]">{{orderStatusOptions[scope.row.mallOrder.orderStatus]}}</el-tag>

                        </span>
                </template>
            </el-table-column>
            <el-table-column align="center" label="是否自提">
                <template slot-scope="scope"><span>

                         <el-tag :type="mentions[scope.row.mallOrder.mention]">{{mentions[scope.row.mallOrder.mention]}}</el-tag>

                        </span>
                </template>
            </el-table-column>
            <el-table-column align="center" label="下单时间" width="160">
                <template slot-scope="scope">
                    <span>{{parseTime(scope.row.mallOrder.orderTime)}}</span>
                </template>
            </el-table-column>
            <!--            <el-table-column align="center" label="支付时间">-->
            <!--                <template slot-scope="scope">-->
            <!--                    <span>{{parseTime(scope.row.mallOrder.payTime)}}</span>-->
            <!--                </template>-->
            <!--            </el-table-column>-->
            <!--            <el-table-column align="center" label="发货时间">-->
            <!--                <template slot-scope="scope">-->
            <!--                    <span>{{parseTime(scope.row.mallOrder.deliverTime)}}</span>-->
            <!--                </template>-->
            <!--            </el-table-column>-->
            <!--            <el-table-column align="center" label="确认收货时间">-->
            <!--                <template slot-scope="scope">-->
            <!--                    <span>{{parseTime(scope.row.mallOrder.confirmTime)}}</span>-->
            <!--                </template>-->
            <!--            </el-table-column>-->
            <!--            <el-table-column align="center" label="退货时间">-->
            <!--                <template slot-scope="scope">-->
            <!--                    <span>{{parseTime(scope.row.mallOrder.backTime)}}</span>-->
            <!--                </template>-->
            <!--            </el-table-column>-->
            <!--            <el-table-column align="center" label="退款时间">-->
            <!--                <template slot-scope="scope">-->
            <!--                    <span>{{parseTime(scope.row.mallOrder.refundTime)}}</span>-->
            <!--                </template>-->
            <!--            </el-table-column>-->
            <!--            <el-table-column align="center" label="拒绝时间">-->
            <!--                <template slot-scope="scope">-->
            <!--                    <span>{{parseTime(scope.row.mallOrder.refuseTime)}}</span>-->
            <!--                </template>-->
            <!--            </el-table-column>-->

            <el-table-column align="center" label="操作" width="230" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button type="info" v-if="canList" size="mini" @click="handleItems(scope.row.mallOrder.id)">详情
                    </el-button>
                    <el-button type="primary" v-if="canUpdate&&type==1" size="mini" @click="handleUpdate(scope)">编辑
                    </el-button>

                    <el-button v-if="canCel&&type==0&&scope.row.mallOrder.cancel" size="mini" type="danger"
                               @click="close(scope.$index)">取消
                    </el-button>
                    <el-button
                            v-if="canPay&&type==0&&scope.row.mallOrder.payStatus==0"
                            size="mini" type="danger"
                            @click="pay(scope.$index)">支付
                    </el-button>
                    <el-button style="margin-top: 5px"
                               v-if="canMention&&type==1&&scope.row.mallOrder.mention==1&&scope.row.mallOrder.payStatus==1&&scope.row.mallOrder.orderStatus!=7&&scope.row.mallOrder.orderStatus!=8"
                               size="mini" type="danger"
                               @click="mention(scope.$index)">提走
                    </el-button>

                </template>
            </el-table-column>

        </el-table>

        <div class="pagination-container" style="margin-top: 20px">
            <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
                           :current-page="listQuery.page" :page-sizes="[10,20,30, 50]" :page-size="listQuery.limit"
                           layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
        </div>


        <el-dialog width="60%" center title="订单详情" v-if="temp.mallOrder" :visible.sync="dialogTableVisible">
            <div class="order-detail">
                <div class="item">
                    <div class="item-con">
                        <span class="key">订单编号</span>
                        <span class="value">{{temp.mallOrder.orderNo}}</span>
                    </div>
                </div>

                <div class="item" v-if="temp.mallOrder.orderType==0">
                    <span class="key">联系电话</span>
                    <span class="value">{{temp.mallOrder.mobile}}</span>
                </div>
                <div class="item" v-if="temp.mallOrder.orderType==0">
                    <span class="key">订单状态</span>
                    <span class="value">{{orderStatusOptions[temp.mallOrder.orderStatus]}}</span>
                </div>
                <div class="item" v-if="temp.mallOrder.orderType==0">
                    <span class="key">是否自提</span>
                    <span class="value">{{mentions[temp.mallOrder.mention]}}</span>
                </div>
                <div class="item">
                    <span class="key">业务类型</span>
                    <span class="value">{{busTypeOptions[temp.mallOrder.busType]}}</span>
                </div>
                <div class="item">
                    <span class="key">订单类型</span>
                    <span class="value">{{orderTypeOptions[temp.mallOrder.orderType]}}</span>
                </div>
                <div class="item" v-if="temp.mallOrder.orderFrom==0">
                    <span class="key">付款状态</span>
                    <span class="value">{{payStatusOptions[temp.mallOrder.payStatus]}}</span>
                </div>
                <div class="item">
                    <span class="key">订单金额</span>
                    <span class="value">{{temp.mallOrder.price}}</span>
                </div>
                <div class="item">
                    <span class="key">订单积分</span>
                    <span class="value">{{temp.mallOrder.point}}</span>
                </div>
                <div class="item">
                    <span class="key">订单优惠券</span>
                    <span class="value">{{temp.mallOrder.coupon}}</span>
                </div>
                <div class="item">
                    <span class="key">订单购物卷</span>
                    <span class="value">{{temp.mallOrder.voucher}}</span>
                </div>
                <div class="item" v-if="temp.mallOrder.orderType==0">
                    <span class="key">物流单号</span>
                    <span class="value">{{temp.mallOrder.logNo}}</span>
                </div>
                <div class="item" v-if="temp.mallOrder.orderType==0">
                    <span class="key">物流公司</span>
                    <span class="value">{{temp.mallOrder.logCompany}}</span>
                </div>
                <div class="item" v-if="temp.mallOrder.orderType==0">
                    <span class="key">收货地址</span>
                    <span class="value">{{temp.mallOrder.address}}</span>
                </div>
                <div class="item">
                    <span class="key">下单时间</span>
                    <span class="value">{{parseTime(temp.mallOrder.orderTime)}}</span>
                </div>
                <!--                <div class="item">-->
                <!--                    <span class="key">支付时间</span>-->
                <!--                    <span class="value">{{parseTime(temp.mallOrder.payStatus)}}</span>-->
                <!--                </div>-->
                <div class="item" v-if="temp.mallOrder.orderType==0">
                    <span class="key">发货时间</span>
                    <span class="value"
                          v-if="temp.mallOrder.deliverTime">{{parseTime(temp.mallOrder.deliverTime)}}</span>
                </div>

                <div class="item">
                    <span class="key">备注</span>
                    <span class="value">{{temp.mallOrder.remark}}</span>
                </div>

            </div>
            <el-divider>订单明细</el-divider>
            <el-table
                    border
                    show-summary
                    :data="temp.mallOrder.items"
                    style="width: 100%">
                <el-table-column
                        align="center"
                        prop="name"
                        label="产品"
                        width="350">
                </el-table-column>
                <el-table-column
                        align="center"
                        label="类别"
                        width="200"
                >
                    <template slot-scope="scope">
                        {{scope.row.skuName?scope.row.skuName:'默认'}}
                    </template>
                </el-table-column>
                <el-table-column
                        align="center"
                        prop="price"
                        label="价格">
                </el-table-column>
                <el-table-column
                        align="center"
                        prop="quantity"
                        label="数量">
                </el-table-column>
                <el-table-column
                        align="center"
                        prop="totalPrice"
                        label="总额">
                    <!--                    <template slot-scope="scope"><span>-->
                    <!--                        {{scope.row.quantity*scope.row.price}}-->
                    <!--                        </span>-->
                    <!--                    </template>-->
                </el-table-column>
            </el-table>

        </el-dialog>


        <el-dialog :title="textMap[dialogStatus]" :visible.sync="dialogFormVisible" v-if="temp.mallOrder">
            <el-form :rules="rules" ref="dataForm" :model="temp" label-position="left" label-width="120px"
                     style='width: 450px; margin-left:50px;'>
                <el-form-item label="单号" prop="orderNo">
                    <el-input v-model="temp.mallOrder.orderNo"></el-input>
                </el-form-item>
                <el-form-item label="用户ID" prop="userId">
                    <el-input v-model="temp.mallOrder.userId"></el-input>
                </el-form-item>
                <el-form-item v-if="type==0" label="总价" prop="price">
                    <el-input v-model="temp.mallOrder.price"></el-input>
                </el-form-item>
                <el-form-item label="物流费" prop="logFee">
                    <el-input v-model="temp.mallOrder.logFee"></el-input>
                </el-form-item>
                <el-form-item label="物流公司" prop="logCompany">
                    <el-input v-model="temp.mallOrder.logCompany"></el-input>
                </el-form-item>
                <el-form-item label="物流单号" prop="logNo">
                    <el-input v-model="temp.mallOrder.logNo"></el-input>
                </el-form-item>
                <el-form-item label="收货地址" prop="address">
                    <el-input v-model="temp.mallOrder.address"></el-input>
                </el-form-item>
                <el-form-item label="订单状态" prop="status">
                    <el-select class="filter-item input" v-model="temp.mallOrder.orderStatus" placeholder="订单状态">
                        <el-option v-for="(item,index) in  orderStatusOptions" :key="item" :label="item"
                                   :value="index">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="支付状态" prop="status">
                    <el-select class="filter-item input" v-model="temp.mallOrder.payStatus" placeholder="支付状态">
                        <el-option v-for="(item,index) in  payStatusOptions" :key="item" :label="item"
                                   :value="index">
                        </el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="下单时间" prop="date">
                    <el-date-picker v-model="temp.mallOrder.orderTime" type="datetime"
                                    value-format="yyyy-MM-dd HH:mm:ss" placeholder="下单时间">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="支付时间" prop="date">
                    <el-date-picker v-model="temp.mallOrder.payTime" type="datetime"
                                    value-format="yyyy-MM-dd HH:mm:ss" placeholder="支付时间">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="发货时间" prop="date">
                    <el-date-picker v-model="temp.mallOrder.deliverTime" type="datetime"
                                    value-format="yyyy-MM-dd HH:mm:ss" placeholder="发货时间">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="确认收货时间" prop="date">
                    <el-date-picker v-model="temp.mallOrder.confirmTime" type="datetime"
                                    value-format="yyyy-MM-dd HH:mm:ss" placeholder="确认收货时间">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="退货时间" prop="date">
                    <el-date-picker v-model="temp.mallOrder.backTime" type="datetime"
                                    value-format="yyyy-MM-dd HH:mm:ss" placeholder="退货时间">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="退款时间" prop="date">
                    <el-date-picker v-model="temp.mallOrder.refundTime" type="datetime"
                                    value-format="yyyy-MM-dd HH:mm:ss" placeholder="退款时间">
                    </el-date-picker>
                </el-form-item>
                <el-form-item label="拒绝时间" prop="date">
                    <el-date-picker v-model="temp.mallOrder.refuseTime" type="datetime"
                                    value-format="yyyy-MM-dd HH:mm:ss" placeholder="拒绝时间">
                    </el-date-picker>
                </el-form-item>

            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="closeDialogForm">取消</el-button>
                <el-button v-if="dialogStatus=='create'" type="primary" @click="createData">确认</el-button>
                <el-button v-else type="primary" @click="updateData">确认</el-button>
            </div>
        </el-dialog>
    </div>
</template>
<style type="stylus">
    .filter-container {
        /*padding-bottom: 20px;*/
    }

    .filter-item {
        margin-bottom: 10px;
    }

    .filter-item.input {
        /*line-height: 60px*/
        margin-right: 10px;
    }
</style>

<style type="stylus" lang="stylus">
    .filter-container {
        padding-bottom: 20px;
    }

    .order-detail
        display flex
        flex-wrap wrap

        .item
            margin-bottom 20px
            display flex
            align-items center
            justify-content flex-start
            width 50%

            .value
                margin-left 20px


</style>

<script>
import {list, save, update, remove, info, profit} from '@/api/mall_order'
    import waves from '@/directive/waves' // 水波纹指令
    import {parseTime} from '@/utils'
    import {mapGetters} from 'vuex'
    import {hasAuth} from '@/utils/auth'
    import {downLoad, downLoads, upload, renew, close, pay, mention} from "../../../api/mall_order";

    export default {
        name: 'test',
        directives: {
            waves
        },
        mounted() {

            if (this.type == 1) {//库房
                this.listQuery.entity.mallOrder.orderType = 0//订单类型为发货
                this.listQuery.entity.mallOrder.payStatus = 1//订单已经支付
            } else {//订单
                // this.listQuery.entity.mallOrder.orderFrom = 0 // 默认
            }
        },
        props: {
            type: {
                type: Number,
                default: 0
            }
        },
        data() {
            return {
                file: null,
                isLoading: false,
                tableKey: 0,
                list: null,
                total: null,
                paw:null,
                listLoading: true,
                listQuery: {
                    json: true,
                    page: 1,
                    limit: 20,
                    order: 'mallOrder.id desc',
                    entity: {
                        mallOrder: {
                            orderNo: null
                            ,
                            userId: null
                            ,
                            price: null
                            ,
                            logFee: null
                            ,
                            logCompany: null
                            ,
                            logNo: null
                            ,
                            userName: null
                            ,
                            mobile: null
                            ,
                            address: null
                            ,
                            orderTime: null,
                            orderTimes: null,
                            payTime: null
                            ,
                            deliverTime: null
                            ,
                            confirmTime: null
                            ,
                            backTime: null
                            ,
                            refundTime: null
                            ,
                            refuseTime: null
                            ,
                            orderStatus: null
                            ,
                            mention: null
                            ,
                            payStatus: null,
                            orderFrom: null,
                            busType: null,
                            orderType: null
                        },
                        user: {
                            name: '',
                            code: ''
                        },
                        fromUser: {
                            name: '',
                            code: ''
                        },
                        shopEntity: {
                            name: '',
                        }

                    }
                },
                orderStatusOptions: ["新订单", "配货中", "已发货", "已收货", "退款中", "已退款", "已拒绝", "已完成", "已取消"],
                payStatusOptions: ["未支付", "已支付"],
                orderTypeOptions: ["发货", "转货"],
                orderFromOptions: ["商城", "后台", "收款"],
                busTypeOptions: ["进货", "调配", "退货", "还货", "自动进货"],
                closedOptions: ["已结束", "未结束"],
                mentions: ["否", "是"],
                tagTypes: ['info', '', 'warning', 'danger', 'warning'],
                temp: {}
                ,
                dialogFormVisible: false,
                dialogTableVisible: false,
                dialogStatus:
                    '',
                textMap:
                    {
                        update: '修改',
                        create:
                            '新增'
                    }
                ,
                rules:
                    {
                        orderNo: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        userId: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        price: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        orderTime: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        payTime: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        deliverTime: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        confirmTime: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        backTime: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        refundTime: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        refuseTime: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        orderStatus: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'blur'
                            }
                        ]
                        ,
                        payStatus: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'blur'
                            }
                        ]
                        ,
                        logFee: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        logCompany: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        logNo: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        userName: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        mobile: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                        ,
                        address: [
                            {
                                required: false, message:
                                    '必填字段', trigger:
                                    'change'
                            }
                        ]
                    }
                ,
                downloadLoading: false,
                qData:
                    {
                        token: '',
                        key:
                            ''
                    }
            }
        },
        created() {
            this.getList()
        },
        computed: {
            ...mapGetters([
                'perms'
            ]),
            getShopName() {
                return process.env.VUE_APP_SHOPNAME;
            }
            ,
            canSave() {
                return hasAuth(this.perms, 'mall:order:save')
            },
            canDownLoad() {
                return hasAuth(this.perms, 'mall:order:downLoad')
            },
            canwuliuDownLoad() {
                return hasAuth(this.perms, 'mall:order:wuliuDownLoad')
            },
            canUpLoad() {
                return hasAuth(this.perms, 'mall:order:upLoad')
            },
            canRenew() {
                return hasAuth(this.perms, 'mall:order:renew')
            },
            canDelete() {

                return hasAuth(this.perms, 'mall:order:delete')
            },
            canPay() {

                return hasAuth(this.perms, 'mall:order:pay')
            },
            canMention() {

                return hasAuth(this.perms, 'mall:order:mention')
            },
            canCel() {

                return hasAuth(this.perms, 'mall:order:cancel')
            },
            canUpdate() {
                return hasAuth(this.perms, 'mall:order:update')
            },
            canList() {
                return hasAuth(this.perms, 'mall:order:list')
            }
        },
        methods: {

            parseTime(time) {
                return parseTime(time)
            },
            handleItems(id) {
                info(id).then(res => {
                    this.temp = res.data
                    this.dialogTableVisible = true
                })
            },
            getList() {
                this.listLoading = true
                const OrderNo = "162972950515224163450,162972923898991163450,162972486024267109432,16297239585198257019,16297224237947224345,162964211319117164924,162963993998788192101,162963987350824192101,162963789114342228379,162963784000765228379,16296323178136221738,16296295741955386152,1629626760083100170266,162955385737687241970,162955192010499242238,16295429643132342653,162954281155522156916,162948276743325242212,162947756169231239868,16291196273471173707,162911850851585113146,162911771196218194884,162911516796220194813,16288666264031752471,162886245916857113762,162885248237150141312,162885162712271240036,16288503954097395582,162877553541993192072,1628773014741887110,162877270477882239819,16287722247060240519,162877151358727119756,162869260106256175575,162869245239618241661,162869154821954128133,162868407521763192101,16286838295604209651,162859232279115239106,16286012296312149467,162860163948666169852,162852051511277103511,162852009649833165214,16285181774659171102,162851810085485149372,162851779810723149372,16285141187312956115,162834997428037169252,162834966854417169252,16283469636989661045,162834577931481168514,162834226235033205966,162833982881065133438,162833912228097205966,16282584658166296730,162843188088111143295,162843163689122123832,162841118826546241317,162825022414054177892,162825306974634186822,162825599114533205216,162825691899775242034,162825808812048140023,16282584658166296730,16281729735252054364,162816800473117131520,16281178419179117873,162811270083063120399,16281178419179117873,162811270083063120399,162809147367051113960,162809087940181113960,162809019799831113960,16280849197629751052,162808301718224191245,16280825863831568907,16280816458015666210,16280799424274133268,162790690484266200362,162790777669424221962,16279081421258585947,16279090660388177498,162790936659364188312,162790950714728177498,16279129556706162870,162791357222794235160,162782397304325241970,162782733220489198724,162782767091733214681,162783029967985190659,162783124070198239001,162783270735028169292,16276482280638140023,16276523963114117321,16275520740176223581,16275582658766688518,16275594140133255037,16275589452429116261,162756204149613239539,162748226985861122874,162748173130570230074,16274681872718663245,162746792959080203174,16274670330733187446,16274032205121150994,162740125034548131520,162739642703145110010,162739473993637169966,16272951624765545125,162704191258761238135,162703733815554148446,16269962901036760699,16269962257825278149,16269945569598655037,162696360532098108928,162696149461831241749,16269609217128241661,162695693249469241750,162695628889851141738,16269551042702185947,16267881254011844918,16267849482502661159,162677942851682237947,162670361954174156764,162669688713910223332,162669596492538213218,16266943758959200362,16266916114528177338,162661716728118186430,16266156502831122979,162661524851680223174,16266132416255069905,162656973723313234765,162656958206245241676,162656946099369212323,162656846044518200688,162656777903832212331,1626561306936766898,162653808935653170226,16265340792135248822,162653338308491121999,16265334357685985947,16265332259360200742,162653318401023200742,162653163224440135741,16265174186081755499,162651579611686120391,16265131437378765638,1626360686839355037,162635812675877142927,162635632411067123536,162635304891222118597,162635257417013118597,162635239873445202694,162635043074575131935,16263456137772387622,162634385546738131300,162634296768195156773,16262764455093737009,162627312020892109644,162627041202579195396,162626950167215195396,162610139666244163569,162609902669265170494,16260983542809230707,162609786775559113767,16260927128168359759,162584058125116153840,162583951294160200072,162583011997492120336,16257400482497266210,162573827833978241327,16255776411534165842,16255775755861129523,162557658797433205966,162557596479594119452,162557581705366178085,16255754037008228203,162557364214489225485,16255705618768583949,162548782734422224652,162548658500032181375,162548502240279106226,16254849307511340904,16254844900634250897,1625484215936550897,162548349617549200362,162531785790818210324,162540378491540130255,162540357809798129523,162540132556330161940,162539839520237231219,16253979153909791243,162539571323514206964,162538345301280184569,162522795347677239920,162522842854977224598,162514160781795241277,16251393599480114488,16251385282168194853,162506782280758127773,162506256491331175859,16250553504277065908,162504913612223202933,162501322606282113267,162497194052011203513,16249710375855462554,16249660826891289729,162496468561664241259,162496247470762156246,162418166026788175299,162402331652192206893,162392691538659234015,162392845978890156470,162393133911670167301,16238330489829455750,16238331009897755750,16238337268805655750,16238337506379155750,1623834443504287446,16238370582303263150,16238375521704140904,16238379807056087446,16238385662639936940,16238387060271466210,16237576876225640904,16237549845394840904,16237548714883540904,162357727779364137935,16235764310876242653,1623576922490440904,16235773811199223555,16235779774559753008,162357896568022127153,162357901396072137935,162358388926383130255,1623653040190045125,162365670799285133320,16236528225351346574,162340555763371109570,16234103243479440904,16234111451844473471,162341292594536198197,16234129592159140904,162333148927689137935,162333123710310157310,162333033981324135741,162333027824972135741,162332767986770145118,162332734780666196633,16233259594038240165,162332528731054231805,162333213884140203174,16233320935294187446,16231507140257466210,16231555107456540904,16230650786961146472,162306515351147160921,162307281927248201443,16230756935416937009,16229877836621169342,16229876591314139046,162298741747913169342,1622980216191639046,16229667509144337134,'jiezhi',16228060548123189507,162280688199865208701,162281372783227203133,16228137730915269905,16228153171315239761,6215177672817196633,1622637873612767893,162263645140049237107,16226420129729156246,162264175095414200362,162264446110578207353,162265074558124118432,16226477324528136926,162265048012022118432,162255647095289238286,162255524479222238286,162255287128980212912,162255049363968167658,16225461104652739793,16225426279278865638,16225370815711295721,16225362742521860504,1622468201587439793,162220566584366240033,16222425268424860362,162221123583597140096,16222151024787207043,162224119714133131880,161476781933384120182,16147688441596837009,161988125160952116875,16202165714108037009,162021916968452177472,16202165972379381297,16208221562762663267,16208236504637140904,16202130814587254783,16203017802151239655,16203917305586874125,162038689383266239542,162039122043487139626,162047621743634239515,162048621598363121383,162134000548465174799,162133763065013146627,162065571005158163047,16181767020727194112,162064487680682108672,162064532114679153513,16206553517262875877,162073841699350141312,162124662701050130255"
                list(this.listQuery).then(response => {
                     this.list = response.data.list
                     this.list = this.list.filter(l => {
                       return OrderNo.indexOf(l.mallOrder.orderNo) < 0
                     })
                    // this.list.forEach(item => {
                    //     if (!item.shopEntity) {
                    //         if ((item.mallOrder.orderType == 0 && item.mallOrder.busType == 1) ||
                    //             (item.mallOrder.orderType == 1 && item.mallOrder.busType == 1)) {
                    //             item.shopEntity.name = process.env.VUE_APP_SHOPNAME;
                    //         }
                    //     }
                    // })
                    this.total = response.data.total
                    this.listLoading = false
                })
            },
            openFile() {
                this.$refs.file.click()
            },
            upload(e) {
                upload(e.target.files[0]).then(res => {
                    this.$notify({
                        title: '成功',
                        message: '上传成功!',
                        type: 'success',
                        duration: 2000
                    })
                    this.getList()
                })
            },
            renew() {
                this.isLoading = true
                renew().then(() => {
                    this.isLoading = false
                    this.$notify({
                        title: '成功',
                        message: '恢复成功',
                        type: 'success',
                        duration: 2000
                    })
                    this.getList()
                })
            },
            profit(){
              this.isLoading = true
              profit(this.listQuery).then(res => {
                this.isLoading = false
                this.$notify({
                  title: '成功',
                  message: '下载成功',
                  type: 'success',
                  duration: 2000
                })
              })
            },
            downLoad(type) {
                this.isLoading = true
                if (type == 1) {
                    downLoad().then(() => {
                        this.isLoading = false
                        this.$notify({
                            title: '成功',
                            message: '下载成功',
                            type: 'success',
                            duration: 2000
                        })
                        this.getList()
                    })
                } else {
                  return
                    downLoads().then(() => {
                        this.isLoading = false
                        this.$notify({
                            title: '成功',
                            message: '下载成功',
                            type: 'success',
                            duration: 2000
                        })
                        this.getList()
                    })
                }
            },
            handleFilter() {
                this.listQuery.page = 1
                this.getList()
            },
            handleSizeChange(val) {
                this.listQuery.limit = val
                this.getList()
            },
            handleCurrentChange(val) {
                this.listQuery.page = val
                this.getList()
            },
            handleModifyStatus(row, status) {
                this.$message({
                    message: '操作成功',
                    type: 'success'
                })
                row.status = status
            },
            beforeFormShow(row) {
                this.resetTemp(row) // 更新数据
                // 存在图片

            },
            afterFormShow(row) {

            },
            beforeFormCommit() {
            },
            resetTemp(row) {

                this.temp = {}
                if (row) {
                    this.temp = JSON.parse(JSON.stringify(row))
                    this.temp.mallOrder.items = []
                }


            },
            handleCreate() {
                this.beforeFormShow()
                this.resetTemp()
                this.dialogStatus = 'create'
                this.dialogFormVisible = true
                this.$nextTick(() => {
                    this.afterFormShow()
                    this.$refs['dataForm'].clearValidate()
                })
            },
            handleDelete(scope) {
                this.index = scope.$index
                // this.beforeFormShow(scope.row)
                // this.temp = Object.assign({}, row) // copy obj
                this.$confirm('此操作将取消订单退回资金, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    // this.$message({
                    //   type: 'success',
                    //   message: '删除成功!'
                    // })
                    this.deleteData()
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    })
                })
            },
            createData() {
                this.$refs['dataForm'].validate((valid) => {
                        if (valid) {
                            this.beforeFormCommit()
                            save(this.temp).then(res => {
                                this.temp = res.data
                                this.list.unshift(this.temp)
                                this.closeDialogForm()
                                this.$notify({
                                    title: '成功',
                                    message: '创建成功',
                                    type: 'success',
                                    duration: 2000
                                })
                            })
                        }
                    }
                )
            },
            deleteData() {
                const ids = [this.list[this.index].mallOrder.id]
                remove({ids: ids}).then(res => {
                    // 从当前队列中移除
                    this.list.splice(this.index, 1)
                    this.$notify({
                        title: '成功',
                        message: '删除成功',
                        type: 'success',
                        duration: 2000
                    })
                })
            },
            close(index) {
                this.$confirm('此操作将取消订单退回资金, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    let orderId = this.list[index].mallOrder.id
                    close(orderId).then(res => {
                        this.$notify({
                            title: '成功',
                            message: '取消成功',
                            type: 'success',
                            duration: 2000
                        })
                        this.list[index].mallOrder = res.data
                    })
                })
            },
            pay(index) {
                this.$confirm('请确认收到款后再进行操作, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    let orderId = this.list[index].mallOrder.id
                    pay(orderId).then(res => {
                        this.$notify({
                            title: '成功',
                            message: '支付成功',
                            type: 'success',
                            duration: 2000
                        })
                        this.list[index].mallOrder = res.data
                    })
                })
            },
            mention(index) {
                this.$confirm('请确认客户拿到产品后再进行操作, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    let orderId = this.list[index].mallOrder.id
                    mention(orderId).then(res => {
                        this.$notify({
                            title: '成功',
                            message: '提走成功',
                            type: 'success',
                            duration: 2000
                        })
                        this.list[index].mallOrder = res.data
                    })
                })
            },
            handleUpdate(scope) {
                this.index = scope.$index
                this.beforeFormShow(scope.row)
                this.dialogStatus = 'update'
                this.dialogFormVisible = true
                this.$nextTick(() => {
                    this.$refs['dataForm'].clearValidate()
                })
            },
            cancel() {

            },
            updateData() {
                this.$refs['dataForm'].validate((valid) => {
                        if (valid) {
                            this.beforeFormCommit()
                            update(this.temp.mallOrder).then(() => {
                                this.list.splice(this.index, 1, this.temp)
                                this.closeDialogForm()
                                this.$notify({
                                    title: '成功',
                                    message: '更新成功',
                                    type: 'success',
                                    duration: 2000
                                })
                            })
                        }
                    }
                )
            },
            closeDialogForm() {
                this.dialogFormVisible = false
            },
            formatJson(filterVal, jsonData) {
                return jsonData.map(v => filterVal.map(j => {
                        return v[j]
                    }
                ))
            },
        }
    }
</script>
